package com.mine;

public class RingQueue {
    public int[] array;
    public int length;
    public int font;
    public int rear;

    public RingQueue(int cap) {
        array = new int[cap];
        font = 0;
        rear = 0;
    }

    public void enqueue(int value) {
        if ((rear + 1) % array.length == font) {
            throw new RuntimeException("满了");
        }
        array[rear++] = value;
        rear = rear % array.length;
    }

    public int dequeue() {
        if (rear == font) {
            throw new RuntimeException("空了");
        }
        int res = array[font++];
        font = font % array.length;
        return res;
    }
}
